import { AutoFight } from "./AutoFight";
import { Language } from "../../../../extend/language/Language";
import { GTextFormat } from "../../../common/GTextFormat";
import { ObjCreate } from "../common/ObjCreate";
import { GButton } from "../../../../com/mui/controls/GButton";
import { DataProvider } from "../../../../fl/data/DataProvider";
import { SkillPanel } from "./SkillPanel";
import { EventName } from "../../mvc/EventName";
import { RadioButtonGroup } from "../../../../fl/controls/RadioButtonGroup";
import { Cache } from "../../cache/Cache";
import { ESkillUseType } from "../../../../Message/Public/ESkillUseType";
import { SkillsUtil } from "../../scene/skill/SkillsUtil";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { GRadioButton } from "../../../../com/mui/controls/GRadioButton";
import { AutoFightInfo } from "./AutoFightInfo";
import { GComboBox } from "../../../../com/mui/controls/GComboBox";
import { GCheckBox } from "../../../../com/mui/controls/GCheckBox";
type int = number;
//class SkillSetPanel
    
    export  class SkillSetPanel /* flash.display.Sprite */
    {
        constructor(arg1: Boolean=false)
        {
            this._autoFightInfo = AutoFight.localAutoFight;
            this._dataArr = [{"name": Language.getString(34046), "index": 0}, {"name": Language.getString(34047), "index": 1}];
            this._btnDic = new Map<any, any> /* flash.utils.Dictionary */();
            
            this.init(arg1);
            return;
        }

        public setIndexComboVisible(arg1: Boolean): void
        {
            this._indexCombo.visible = arg1;
            return;
        }

        public setRadioBtnVisible(arg1: Boolean): void
        {
            var loc1=null;
            var loc2=0;
            var loc3=this._btnDic;
            for(loc1 of loc3) 
            {
                loc1.visible = arg1;
            }
            return;
        }

        /* internal  */init(arg1: Boolean): void
        {
            var loc5=null;
            var loc8=null;
            var loc1=new GTextFormat("", 13, 16776960);
            this._autoUseSkillCb = ObjCreate.createCheckBox(Language.getString(34007), 5, 0, 180, 25, this, "CheckBoxStyle");
            this._autoUseSkillCb.setStyle("textFormat", loc1);
            this._autoUseSkillCb.addEventListener(flash.events.Event.CHANGE, this.onAutoUseSkillCbChangeHandler);
            var loc2=new GButton();
            loc2.label = Language.getString(34008);
            loc2.styleName = "Button";
            loc2.width = 70;
            loc2.height = 22;
            loc2.x = 110;
            loc2.y = 0;
            loc2.addEventListener(flash.events.MouseEvent.CLICK, this.onAutoAddBtnClickHandler);
            this.addChild(loc2);
            var loc3;
            (loc3 = new DataProvider()).addItem({"id": 0, "label": Language.getString(34046)});
            loc3.addItem({"id": 1, "label": Language.getString(34047)});
            this._indexCombo = ObjCreate.createGComboBox(185, 0, 80, 20, loc3, this);
            this._indexCombo.addEventListener(flash.events.Event.CHANGE, this.onIndexComboChangeHandler);
            this._skillPanel = new SkillPanel(this.autoSkillNum, false, arg1);
            this._skillPanel.x = 0;
            this._skillPanel.y = 35;
            this._skillPanel.addEventListener(EventName.SkillItemChange, this.onSkillItemChangeHandler);
            this.addChild(this._skillPanel);
            this._clearSkillTxt = ObjCreate.createTextField("", 430, 55, 40, 20, this);
            this._clearSkillTxt.filters = [];
            this._clearSkillTxt.htmlText = "<font color=\'#00ff00\'><a href=\'event: 0\'><u>" + Language.getString(34016) + "</u></a></font>";
            this._clearSkillTxt.addEventListener(flash.events.TextEvent.LINK, this.onClearSkillHandler);
            if (arg1) 
            {
                this._clearSkillTxt.x = 215;
                this._clearSkillTxt.y = 90;
            }
            var loc4=new RadioButtonGroup("rbg");
            var loc6=470;
            var loc7=30;
            var loc9=0;
            while (loc9 < 2) 
            {
                (loc5 = ObjCreate.createRadioButton(this._dataArr[loc9].name, loc6, loc7, 80, 20, this, "GRadioButtonBig")).addEventListener(flash.events.MouseEvent.CLICK, this.onRadioBtnClickHandler);
                loc5.value = this._dataArr[loc9].index;
                loc5.group = loc4;
                loc7 = loc7 + loc5.height;
                this._btnDic[this._dataArr[loc9].index] = loc5;
                ++loc9;
            }
            return;
        }

        /* internal  */onAutoUseSkillCbChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            if (this._autoUseSkillCb.selected) 
            {
                this._autoFightInfo.skillIdx = this._index;
            }
            else 
            {
                this._autoFightInfo.skillIdx = -1;
            }
            return;
        }

        /* internal  */onIndexComboChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            this._index = this._indexCombo.selectedIndex;
            this._autoFightInfo.skillIdx = this._index;
            this._skillPanel.clean();
            this._skillPanel.showSkill(this._index, false);
            this._autoFightInfo.alter = true;
            return;
        }

        /* internal  */onAutoAddBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc4=null;
            var loc8=0;
            var loc9=0;
            this._skillPanel.clean();
            var loc1=this._autoFightInfo.getSkillArr()[this._index];
            var loc2=Cache.instance.skill.skills;
            var loc3=[];
            var loc5=0;
            while (loc5 < loc2.length) 
            {
                if ((loc4 = loc2[loc5]).useType == ESkillUseType._ESkillUseTypeInitiative && SkillsUtil.instance.isCanAddToAutoFightList(loc4.skillId, false)) 
                {
                    loc3.push(loc2[loc5]);
                }
                ++loc5;
            }
            var loc6=(loc3.length - 1);
            while (loc6 >= 0) 
            {
                loc8 = 0;
                while (loc8 < loc1.length) 
                {
                    if (loc3[loc6].skillId == loc1[loc8]) 
                    {
                        loc3.splice(loc6, 1);
                        break;
                    }
                    ++loc8;
                }
                --loc6;
            }
            var loc7=0;
            while (loc7 < loc1.length) 
            {
                if (loc1[loc7] == 0) 
                {
                    loc9 = 0;
                    while (loc9 < loc3.length) 
                    {
                        this._autoFightInfo.getSkillArr()[this._index][loc7] = loc3[loc9].skillId;
                        this._autoFightInfo.getSkillShowArr()[this._index][loc7] = loc3[loc9].skillId;
                        loc3.splice(loc9, 1);
                    }
                }
                ++loc7;
            }
            this._skillPanel.showSkill(this._index);
            this._autoFightInfo.alter = true;
            return;
        }

        /* internal  */onSkillItemChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            this._autoFightInfo.alter = true;
            return;
        }

        /* internal  */onClearSkillHandler(arg1: Object /* flash.events.TextEvent */): void
        {
            this._autoFightInfo.getSkillArr()[this._index] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
            this._autoFightInfo.getSkillShowArr()[this._index] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
            AutoFight.localAutoFight.alter = true;
            this._skillPanel.clean();
            this._skillPanel.showSkill(this._index);
            Dispatcher.dispatchEvent(new DataEvent(EventName.SaveAutoFightInfo));
            return;
        }

        /* internal  */onRadioBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=arg1.target as GRadioButton;
            this._index = loc1.value as int;
            this._autoFightInfo.skillIdx = this._index;
            this._skillPanel.clean();
            this._skillPanel.showSkill(this._index, false);
            this._autoFightInfo.alter = true;
            return;
        }

        public resetSkillPanel(): void
        {
            var loc1=null;
            this._skillPanel.clean();
            this._index = this._autoFightInfo.skillIdx;
            if (!(this._index == -1) && this._index < this._autoFightInfo.getSkillArr().length) 
            {
                this._indexCombo.selectedIndex = this._index;
                this._skillPanel.showSkill(this._index, false);
                loc1 = this._btnDic[this._index] as GRadioButton;
                loc1.selected = true;
                this._autoUseSkillCb.selected = true;
            }
            else 
            {
                this._index = this._indexCombo.selectedIndex;
                this._skillPanel.showSkill(this._indexCombo.selectedIndex, false);
                this._autoUseSkillCb.selected = false;
            }
            return;
        }

        /* internal */ /* const */autoSkillNum: int=10;

        /* internal */ /* var */_autoFightInfo: AutoFightInfo;

        /* internal */ /* var */_skillPanel: SkillPanel;

        /* internal */ /* var */_clearSkillTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_indexCombo: GComboBox;

        /* internal */ /* var */_autoUseSkillCb: GCheckBox;

        /* internal */ /* var */_dataArr: Array<any>;

        /* internal */ /* var */_btnDic: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_index: int;
    }
